package com.shujia.git;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

public class Demo2Jdbc {
    public static void main(String[] args) throws Exception {


        //1、加载驱动

        Class.forName("com.mysql.jdbc.Driver");


        //2、建立连接

        Connection con = DriverManager.getConnection("jdbc:mysql://node3:3306/shujia", "root", "123456");


        //3、执行sql

        PreparedStatement stat = con.prepareStatement("select name,age from user");

        ResultSet resultSet = stat.executeQuery();


        //4、解析返回的结果

        while (resultSet.next()) {
            String name = resultSet.getString("name");
            int age = resultSet.getInt("age");

            System.out.println(name + "\t" + age);
        }


        //5、关闭连接
        con.close();

    }
}
